package com.ktkq.service.classroom.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ktkq.dao.classroom.ClassRoomMapper;
import com.ktkq.service.classroom.ClassRoomService;
import com.ktkq.util.PageFinder;
import com.ktkq.util.Pageing;
import com.ktkq.util.TimeUtil;
import com.ktkq.util.font.UploadExcel;
import com.ktkq.vo.ClassRoom;


@Service("classRoomService")
@Transactional
public class ClassRoomServiceImpl implements ClassRoomService{

	@Autowired
	ClassRoomMapper classRoomMapper;
	
	@Override
	public PageFinder<ClassRoom> queryList(Pageing pageing) {
		
		PageFinder<ClassRoom> pageFinder = new PageFinder<ClassRoom>();
		
		pageFinder.setRowCount(classRoomMapper.pageCount(pageing));
		pageFinder.setDataList(classRoomMapper.queryList(pageing));
		
		return pageFinder;
	}

	@Override
	public void insert(ClassRoom t) {
		
		classRoomMapper.insert(t);
	}

	@Override
	public void update(ClassRoom t) {
		
		classRoomMapper.update(t);
	}

	@Override
	public void delete(ClassRoom t) {
		
		classRoomMapper.delete(t);
	}

	@Override
	public List<ClassRoom> queryListById(int id) {
		
		return classRoomMapper.queryById(id);
	}

	@Override
	public List<ClassRoom>  UploadExcel(String filePath,ClassRoom t) {
		
	List<ClassRoom>  lss = new ArrayList<ClassRoom>();
	List<List<String>> list = new UploadExcel(filePath).AnalysisExcel();
	 if(list.size()!=0){
		 for(List<String> ls :list){
			 String time = new TimeUtil().getTime();
			 ClassRoom classRoom = new ClassRoom();			
			     classRoom.setAcademyId(t.getAcademyId());
			     classRoom.setAcademy(t.getAcademy());
			     classRoom.setClassName(ls.get(1));	
			     classRoom.setTime(time);
				 lss.add(classRoom);
				 classRoomMapper.insert(classRoom); 
		 } 
	 }
	
	return lss;
	}
	
}
